﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace MvcApplication.utls
{
   public static class md5helper
    {
        private const string saltStr= "3Hjk$O375&kKH#";

        /// <summary>
        /// MD532免密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string entryMd5(this string str,string salt= saltStr)
        {
            str = str + saltStr;
            // 创建MD5对象
            MD5 md5 = MD5.Create();
            // 需要将字符串转换成字节数组
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            // 返回一个加密好的字节数组
            byte[] MD5Buffer = md5.ComputeHash(buffer);

            // 将字节数组每个元素ToString(x) 16进制
            string s2 = "";
            foreach (var item in MD5Buffer)
            {
                s2 += item.ToString("x2");
            }
            return s2;
        }
    }
}
